import {reqCartList} from '@/api'
import { Message } from 'element-ui'
const actions ={
    //购物车商品列表
    async getCartList({commit}){
        const result =await reqCartList()
        if(result.code ===200){
            commit('SAVE_CART_LIST',result.data)
        }else{
            Message.error(result.message)
        }
    }
}
const mutations={
    SAVE_CART_LIST(state,list){
        state.cartList= list
    }
}

const state = {
   cartList:[{cartInfoList:[]}]
}

const getters = {
    cartInfoList(state){
        return state.cartList[0]? state.cartList[0].cartInfoList:[]
    }
}

export default {
    namespaced:true,
    actions,
    mutations,
    state,
    getters,
}